package com.web.controller;

import com.web.entity.PageVO;
import com.web.entity.ResponseResult;
import com.web.entity.Student;
import com.web.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学生控制器
 */
@CrossOrigin //解决跨域问题
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;
    @RequestMapping("/findStudentPage")
    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
        PageVO page = studentService.findStudentPage(current, pageSize);
        return new ResponseResult(200,"OK",page);
    }

    @RequestMapping("/addStudent")
    public ResponseResult addStudent(Student student){
        studentService.addStudent(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping("/updateStudent")
    public ResponseResult updateStudent(Student student){
        studentService.updateStudent(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping("/deleteStudent")
    public ResponseResult deleteStudent(int id){
        studentService.removeStudent(id);
        return new ResponseResult(200,"OK",null);
    }

}
